package com.base.testmvvm;

import android.app.Application;
import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.support.annotation.NonNull;

import com.base.testmvvm.database.AppDatabase;
import com.base.testmvvm.database.OrderDao;
import com.base.testmvvm.database.OrderDaoImpl;

public class MyApplication extends Application {
    private OrderDao orderDao;
    private static Application application;
    public static AppDatabase DB_INSTANCE;
    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        buildDb();
        orderDao = new OrderDaoImpl();

    }


    public static void buildDb() {
        DB_INSTANCE = Room.databaseBuilder(getInstance(), AppDatabase.class, "troy_db").addCallback(new RoomDatabase.Callback() {
            @Override
            public void onCreate(@NonNull SupportSQLiteDatabase db) {
                super.onCreate(db);
            }

            @Override
            public void onOpen(@NonNull SupportSQLiteDatabase db) {
                super.onOpen(db);
            }
        }).allowMainThreadQueries().build();
    }

    public static Application getInstance() {
        return application;
    }

    public OrderDao getOrderDao() {
        return orderDao;
    }

}
